<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\user;

use App\Dao\PlatformDao;
use App\Dao\PlatformOrderDao;
use App\Dao\UserAddrDao;
use App\Request\User\Channel\ChannelBuyRequest;
use App\Request\User\UserAddr\CreateRequest;
use App\Request\User\UserAddr\EditRequest;
use App\Middleware\User\UserMiddleware;

use App\Service\User\PlatformOrderService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 渠道商控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\user
 */
class ChannelController extends Controller
{

    /**
     * 平台商品Dao
     * @Inject
     * @var PlatformDao
     */
    private $platform_dao;


    /**
     * 平台订单服务
     * @Inject
     * @var PlatformOrderService
     */
    private $platform_order_service;

    /**
     * 获取渠道商
     *
     */
    public function get()
    {
        $result = $this->platform_dao->first([
            'type' => $this->platform_dao::TYPE_CHANNEL
        ]);

        $this->success($result);
    }

    /**
     * 购买渠道商
     *
     * @return mixed
     */
    public function buy()
    {
        $id = (int)$this->request->input('id', 0);

        $channel = (string)$this->request->input('channel', 0);

        $result = $this->platform_order_service->buy($id, $channel);

        $this->success($result);
    }
}